<?php

namespace app\models;

use Yii;
use yii\data\ActiveDataProvider;
use app\models\GkyQyh;

/**
 * This is the model class for table "gky_qyh_app".
 *
 * @property integer $id
 * @property integer $agentid
 * @property string $name
 * @property integer $report_location_flag
 * @property string $logo_mediaid
 * @property string $description
 * @property string $redirect_domain
 * @property integer $isreportuser
 * @property integer $isreportenter
 * @property integer $qid
 * @property string $addtime
 *
 * @property GkyQyh $gkyQyh
 */
class GkyQyhApp extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gky_qyh_app';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name','qid'], 'required'],
            [['report_location_flag', 'isreportuser', 'isreportenter', 'qid'], 'integer'],
            [['addtime'], 'safe'],
            [['name'], 'string', 'max' => 64],
            [['logo_mediaid', 'description', 'redirect_domain'], 'string', 'max' => 256],
        ];
    }

    public function getGkyQyh(){

        return $this->hasOne(GkyQyh::className(), ['id'=>'qid']);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'agentid'=>'Agentid',
            'name' => '应用名称',
            'report_location_flag' => 'Report Location Flag',
            'logo_mediaid' => 'Logo Mediaid',
            'description' => 'Description',
            'redirect_domain' => 'Redirect Domain',
            'isreportuser' => 'Isreportuser',
            'isreportenter' => 'Isreportenter',
            'qid' => 'Qid',
            'addtime' => 'Addtime',
        ];
    }

    public static function findAppsByQyid($qyid){

        $query = GkyQyhApp::find()->where(['qid'=>$qyid]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            //分页
            'pagination' => [
                'pageSize' => 10,
            ],
            //排序
            'sort'=>[
                'defaultOrder'=>[
                    'id'=>SORT_ASC,
                ]
            ]
        ]);

        return $dataProvider;
    }
}
